﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class User_RequestInformation : System.Web.UI.Page
{
    BankDataDataContext db = new BankDataDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Roles.IsUserInRole("User"))
        {
            Response.Redirect("~/Account/Login.aspx");
        }
        string creditRequestId = null;
        if (Session["requestId"] != null)
        {
            creditRequestId = Session["requestId"].ToString();
        }
        if (creditRequestId != null)
        {
            var requests = from request in db.CreditRequests where request.CreditRequestId == Convert.ToInt32(creditRequestId) select request;
            CreditList.Enabled = false;
            TermLength.Text = requests.First().TermLength.ToString();
            TermLength.Enabled = false;
            Amount.Text = requests.First().Amount.ToString();
            Amount.Enabled = false;
            CurrencyList.Enabled = false;
            OperatorComment.Text = requests.First().OperatorComments;
        }
    }

    protected void CurrencyList_DataBound(object sender, EventArgs e)
    {
        string creditRequestId = null;
        if (Session["requestId"] != null)
        {
            creditRequestId = Session["requestId"].ToString();
        }
        if (creditRequestId != null)
        {
            var requests = from request in db.CreditRequests where request.CreditRequestId == Convert.ToInt32(creditRequestId) select request;
            CurrencyList.Items.FindByValue(requests.First().CurrencyId.ToString()).Selected = true;
        }
    }

    protected void CreditList_DataBound(object sender, EventArgs e)
    {
        string creditRequestId = null;
        if (Session["requestId"] != null)
        {
            creditRequestId = Session["requestId"].ToString();
        }
        if (creditRequestId != null)
        {
            var credit = from request in db.CreditRequests where request.CreditRequestId == Convert.ToInt32(creditRequestId) select request.Credit;
            string creditId = credit.First().CreditID.ToString();
            if (creditId != null)
            {
                CreditList.Items.FindByValue(creditId).Selected = true;
            }
        }
    }
}